<?php
define('KE', 1);
define('IN_SCRIPT', 1);
define('HESK_PATH', '../');
define('HESK_NO_ROBOTS', 1);

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
require(HESK_PATH . 'inc/database.inc.php');

hesk_session_start();
hesk_dbConnect();

if (!$_SESSION['isadmin']) {
    exit();
}

/* Print header */
require_once(HESK_PATH . 'inc/header.admin.inc.php');

/* Print admin navigation */
require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');


if (isset($_POST['submit'])) {
    $product_name_1 = $_POST['product_name_1'];
    $product_desc_1 = $_POST['product_desc_1'];
    $product_link_1 = $_POST['product_link_1'];

    $product_name_2 = $_POST['product_name_2'];
    $product_desc_2 = $_POST['product_desc_2'];
    $product_link_2 = $_POST['product_link_2'];

    $sql = "UPDATE hesk_promo SET name = '$product_name_1', description = '$product_desc_1', link = '$product_link_1' WHERE id = 1";
    hesk_dbQuery($sql);
    
    $sql = "UPDATE hesk_promo SET name = '$product_name_2', description = '$product_desc_2', link = '$product_link_2' WHERE id = 2";
    hesk_dbQuery($sql);
}

$sql = 'SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'promo`';
$result = hesk_dbQuery($sql);

$row = hesk_dbFetchAssoc($result);

$product_name_1 = $row['name'];
$product_desc_1 = $row['description'];
$product_link_1 = $row['link'];

$row = hesk_dbFetchAssoc($result);

$product_name_2 = $row['name'];
$product_desc_2 = $row['description'];
$product_link_2 = $row['link'];
?>
<br />

<form name="pe_form" action="pe.php" method="post">
    <p>Produk 1</p>
    <table width="100%" border="1" cellspacing="0" cellpadding="3">
        <tr>
            <td>Nama</td>
            <td><input type="text" style="width: 40%" name="product_name_1" value="<?php echo $product_name_1; ?>"></input></td>
        </tr>
        <tr>
            <td>Deskripsi</td>
            <td><input type="text" style="width: 90%" name="product_desc_1" value="<?php echo $product_desc_1; ?>"></input></td>
        </tr>
        <tr>
            <td>Link</td>
            <td><input type="text" style="width: 90%" name="product_link_1" value="<?php echo $product_link_1; ?>"></input></td>
        </tr>
    </table>
    <br />
    <p>Produk 2</p>
    <table width="100%" border="1" cellspacing="0" cellpadding="3">
        <tr>
            <td>Nama</td>
            <td><input type="text" style="width: 40%" name="product_name_2" value="<?php echo $product_name_2; ?>"></input></td>
        </tr>
        <tr>
            <td>Deskripsi</td>
            <td><input type="text" style="width: 90%" name="product_desc_2" value="<?php echo $product_desc_2; ?>"></input></td>
        </tr>
        <tr>
            <td>Link</td>
            <td><input type="text" style="width: 90%" name="product_link_2" value="<?php echo $product_link_2; ?>"></input></td>
        </tr>
    </table>

    <br />
    <input type="submit" name="submit" value="Simpan"></input>
</form>

<?php
hesk_dbClose();
require_once(HESK_PATH . 'inc/footer.inc.php');
?>
